// 类名：前缀 + 组件名 + 自定义名
// pro-button-primary

// BEM  a-b__c--d
// Block
// Element --tag
// Modifier --lg --sm

type BEMType = string | [string, 'B' | 'E' | 'M', ...unknown[]]

export function useClassName(componentName: string) {
  const prefix = 'pro'
  const componentClass = `${prefix}-${componentName}`

  const cls = (...arg: BEMType[]) => {
    if (arg.length) {
      return arg.reduce((prev, cur) => {
        if (Array.isArray(cur)) {
          const str = cur[0]
          const type = cur[1]
          if (type === 'E')
            return `${prev}__${str}`
          else if (type === 'M')
            return `${prev}--${str}`
        }
        return `${prev}-${cur}`
      }, componentClass) as string
    }
    return componentClass
  }

  return { cls }
}
